package test.aat.dxfy.demo01;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLConnection;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import com.aat.dxfy.utils.Atools;

public class KuanKeUserCreate {

	public static void main(String[] args) throws Exception {
		for (int j = 6000; j < 10000; j++) {
			System.out.println("INSERT INTO `ts_group_user` VALUES ('"+j+"', '"+(j%42)+"', '0', '0', '"+(1462523461+j)+"');");
		}
	}

	public static void u100() throws Exception {
		File f = new File("E:\\易金融\\宽客\\自有操作账户.txt");
		BufferedReader br = new BufferedReader(new FileReader(f));
		String s = "";
		int i = 0, j = 0;
		String[] ss = { "吴新", "李玲", "温珂", "李跃", "陈亮", "张利娟", "耿晓娜", "吴兴鲁", "赵永磊", "who" };
		while ((s = br.readLine()) != null) {
			i++;
			String t = "E:\\粉丝账户" + (j + 1) + (ss[j]) + ".txt";
			Atools.writeStrNextLine(t, s);
			System.out.println("------> " + i);
			if (i % 100 == 0) {
				j++;
			}
		}
		br.close();
	}

	public static void users() throws Exception {
		File f = new File("E:\\易金融\\宽客\\自有操作账户.txt");
		BufferedReader br = new BufferedReader(new FileReader(f));
		String s = "";
		int i = 10;
		while ((s = br.readLine()) != null) {
			i++;
			String e = s.split("----")[0];
			String sql = "update ts_user set email='" + e + "' where userid=" + i + ";";
			String sql2 = "update ts_user_info set email='" + e + "' where userid=" + i + ";";
			Atools.writeStrNextLine("E:\\1.sql", sql);
			Atools.writeStrNextLine("E:\\2.sql", sql2);
			System.out.println("------> " + i);
		}
		br.close();
	}

	public static void comments() throws Exception {
		File f = new File("E:\\comments.txt");
		BufferedReader br = new BufferedReader(new FileReader(f));
		String s = "";
		int i = 1;
		while ((s = br.readLine()) != null) {
			i++;
			//
			int articleid = (int) (4 + Math.random() * 18);
			int userid = (int) (10 + Math.random() * 10000);
			int addtime = 1462935550 + userid;
			String sql = "insert into ts_article_comment(commentid,articleid,userid,content,addtime) " + "values(" + i
					+ "," + articleid + "," + userid + ",'" + s + "'," + addtime + ");";
			System.out.println(sql);
		}
		br.close();
		// g更新评论表数据
		// UPDATE ts_article Q , (SELECT A.articleid,COUNT(B.articleid) as c
		// FROM ts_article A LEFT JOIN ts_article_comment B ON
		// A.articleid=B.articleid GROUP BY A.articleid ) W SET
		// Q.count_comment=W.c WHERE Q.articleid=W.articleid;
	}

	public static void img2() throws Exception {

		File dir = new File("E:\\imgs");
		File[] imgs = dir.listFiles();
		int i = 8925;
		for (File file : imgs) {
			i++;
			if (i <= 10010) {
				Atools.copy(file, "E:\\imgs\\" + i + ".jpg");
				System.out.println("--> " + i);
			} else {
				break;
			}

		}
	}

	public static void img() throws Exception {

		File f = new File("E:\\imgs.txt");
		BufferedReader br = new BufferedReader(new FileReader(f));
		int id = 2238;
		String s = "";
		while ((s = br.readLine()) != null) {
			id++;
			URL url = new URL(s);
			URLConnection con = url.openConnection();
			con.connect();
			InputStream is = con.getInputStream();
			OutputStream os = new FileOutputStream("E:\\imgs\\" + id + ".jpg");
			byte[] bs = new byte[102400];
			int i = 0;
			while ((i = is.read(bs)) > 0) {
				os.write(bs, 0, i);
			}
			os.flush();
			os.close();
			is.close();

		}
		br.close();
	}

	public static void sql() throws Exception {
		String salt = "4b459ea1a5917be436df5f0bd5b3c4ad";// MD5.digest("1")
		String pwd = getMd5((salt + "qq1236").getBytes());// 045a8c004bcb8e9b02282a39493438d7

		File f = new File("E:\\names.txt");
		BufferedReader br = new BufferedReader(new FileReader(f));
		int i = 9;
		String s = "";
		while ((s = br.readLine()) != null) {//
			i++;
			String email = Atools.birthWebCode(4) + i + "@163.com";
			String sql = "INSERT INTO ts_user (userid, pwd, salt, email) VALUES('" + i + "','" + pwd + "','" + salt
					+ "','" + email + "'); ";
			String sql2 = "INSERT INTO ts_user_info (userid, locationid, fuserid, username,email,sex,roleid,path,face,ip,comefrom,count_score,count_follow,count_followed,count_group,count_topic,isadmin,isenable,isverify,isrenzheng,isrecommend,signin,addtime,uptime)"
					+ " VALUES(" + i + ",0,0,'" + s + "','" + email + "',0,1,'0/0','0/0/" + i
					+ ".jpg','211.103.170.155',9,55,0,0,0,0,0,0,0,0,0,0,1462857305,1462857316); ";
			Atools.writeStrNextLine("E:\\1.sql", sql);
			Atools.writeStrNextLine("E:\\2.sql", sql2);
			System.out.println("---> " + i);
		}
		br.close();
	}

	public static String md5(String plainText) {
		byte[] secretBytes = null;
		try {
			secretBytes = MessageDigest.getInstance("md5").digest(plainText.getBytes());
		} catch (NoSuchAlgorithmException e) {
			throw new RuntimeException("没有md5这个算法！");
		}
		String md5code = new BigInteger(1, secretBytes).toString(16);
		for (int i = 0; i < 32 - md5code.length(); i++) {
			md5code = "0" + md5code;
		}
		return md5code;
	}

	public static String getMd5(byte[] buffer) throws NoSuchAlgorithmException {
		String s = null;
		char hexDigist[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(buffer);
		byte[] datas = md.digest(); // 16个字节的长整数
		char[] str = new char[2 * 16];
		int k = 0;
		for (int i = 0; i < 16; i++) {
			byte b = datas[i];
			str[k++] = hexDigist[b >>> 4 & 0xf];// 高4位
			str[k++] = hexDigist[b & 0xf];// 低4位
		}
		s = new String(str);
		return s;
	}
}
